﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.Library;
using System.Data;
using IHISCETeim.BLL;
using IHISCETeim.Model;

namespace IHISCETeim.Web.MachineSys.MarketModel
{
    public partial class MBaoYangListEasyUI : EasyUIPageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看, Permission.修改, Permission.新增, Permission.删除 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "MBaoYangListEasyUI";
            }
        }

        #region 属性 (查询条件)


        protected string JXS
        {
            get
            {
                return GetRequestValue<string>("JXS", "");

            }
        }
        protected string JH
        {
            get
            {
                return GetRequestValue<string>("JH", "");

            }
        }
        protected string CKDH
        {
            get
            {
                return GetRequestValue<string>("CKDH", "");

            }
        }
        protected string PZH
        {
            get
            {
                return GetRequestValue<string>("PZH", "");

            }
        }
        protected string SQSJFrom
        {
            get
            {
                return GetRequestValue<string>("SQSJFrom", "");

            }
        }
        protected string SQSJTo
        {
            get
            {
                if (string.IsNullOrEmpty(SQSJFrom))
                {
                    return "";
                }
                else
                {
                    string todate = GetRequestValue<string>("SQSJTo", "");
                    if (string.IsNullOrEmpty(todate))
                        return Convert.ToDateTime(SQSJFrom).AddDays(1).ToShortDateString();
                    else
                        return todate;
                }

            }
        }
        
       

        #endregion

        /// <summary>
        /// 排序字段 值为 id
        /// </summary>
        protected override string orderField
        {
            get
            {
                return string.IsNullOrEmpty(base.orderField) ? "id" : base.orderField;
            }
        }
        /// <summary>
        ///  排序方式 desc或 asc
        /// </summary>
        protected override string orderDirection
        {
            get
            {
                return string.IsNullOrEmpty(base.orderDirection) ? "DESC" : base.orderDirection;
            }
        }


        protected override string SQLSort
        {
            get
            {
                return (orderField + " " + orderDirection);
            }
        }

        protected string GetSQLWhere()
        {
            string wheresql = "";
            string sqlcommonFiled = "";
            if (!string.IsNullOrEmpty(JXS))
            {
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator(" JXS ", QueryOperatorsEnum.包含, JXS);
                wheresql = sqlcommonFiled;
            }






            if (!string.IsNullOrEmpty(SQSJFrom))
            {
                string DOWNSQL = QueryOperatorsEnumHelper.ConvertCommonOperator(" SQSJ ", QueryOperatorsEnum.范围, SQSJFrom + "|" + SQSJTo);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + DOWNSQL;
                }
                else
                {
                    wheresql = DOWNSQL;
                }
            }

            if (!string.IsNullOrEmpty(JH))
            {
                string DOWNSQL = QueryOperatorsEnumHelper.ConvertCommonOperator(" JH ", QueryOperatorsEnum.包含, JH);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + DOWNSQL;
                }
                else
                {
                    wheresql = DOWNSQL;
                }
            }
            if (!string.IsNullOrEmpty(CKDH))
            {
                string DOWNSQL = QueryOperatorsEnumHelper.ConvertCommonOperator(" CKDH ", QueryOperatorsEnum.包含, CKDH);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + DOWNSQL;
                }
                else
                {
                    wheresql = DOWNSQL;
                }
            }
            if (!string.IsNullOrEmpty(PZH))
            {
                string DOWNSQL = QueryOperatorsEnumHelper.ConvertCommonOperator(" PZH ", QueryOperatorsEnum.包含, PZH);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + DOWNSQL;
                }
                else
                {
                    wheresql = DOWNSQL;
                }
            }

            return wheresql;
        }

        protected override string query()
        {
            DataTable dts = null;
            dts = MBaoYangController.GetPagination(GetSQLWhere(), pageNum, numPerPage, SQLSort, ref TotalCount);
            return ToDataGridJson(dts, TotalCount, null).ToString();
          
        }

        protected override string editrow()
        {
            int id = GetRequestValue<int>("id", 0);
            MBaoYangInfo obj = MBaoYangController.GetByID(id);
            obj.CKSJ = GetRequestValue<string>("CKSJ", "");
            obj.CKDH = GetRequestValue<string>("CKDH", "");
            obj.PZH = GetRequestValue<string>("PZH", "");
            return MBaoYangController.Update(obj) ? "" : "更新失败";
        }
    }
}